package com.mall.controller.backend;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mall.common.Const;
import com.mall.common.ServerResponse;
import com.mall.pojo.MmallUser;
import com.mall.service.IUserService;

/**
 * 管理员
 * @author ASUS
 *
 */
@Controller
@RequestMapping("/manage/user/")
public class UserManagerController {
	
	@Autowired
	private IUserService service;
	
	@RequestMapping("/login")
	@ResponseBody
	public ServerResponse<MmallUser> login(String username, String password,HttpSession session){
		
	 	
		ServerResponse<MmallUser> response = service.login(username, password);
		if(response.isSuccess()){
			MmallUser user = response.getData();
			//0 是普通用户, 1是管理员
			if( user.getRole() == 1 ){
				//说明登录的是管理员
				session.setAttribute(Const.CURRENT_USER, user);
				return response;
			}else{
				return ServerResponse.createByErrorMessage("您不是管理员,无法登录");
			}
		}
		
		return response;
	}
	
	
}
